<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="empty" style="margin-top: 100rpx;padding-bottom: 100rpx;" v-if="!loadmore">
			<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<view class="min30_rl background_f rad1 pad20 row" style="margin-top: 30rpx;" v-for="(item,index) in list"
			v-else>
			<view class="column font600 col3 size30" @click="onReturn(item)">
				收货人：{{ item.username }}
				<view class="font500 size26 mintop30">
					联系电话：{{ item.phone }}
				</view>
			</view>
			<view class="minau minright0 align_item_c column">
				<view class="col3 size26 font500 row "
					@click="$jump.nav('/mypackage/user/address_info?type=' + 0 + '&id=' + item.id + '&username=' + item.username + '&phone=' + item.phone)">
					<u-icon name="edit-pen" color="#333" size="16"></u-icon>
					编辑
				</view>
				<!-- <view class="col3 size26 font500 row mintop30">
					<u-icon name="trash" color="red" size="16"></u-icon>
					删除
				</view> -->
			</view>

			<!-- <view class="row font500 col3 size26 mintop30">
				联系电话：{{ item.phone }}
				<view class="minau minright0 col3 size26 font500 row align_item_c">
					<u-icon name="trash" color="red" size="16"></u-icon>
					删除
				</view>
			</view> -->
		</view>
		<view style="margin-top: 50rpx;"><u-loadmore :status="status" /></view>
		<view class="posrel min30_rl" :style="{ top: pageHeight + 'px' }">
			<u-button text="添加取货人" icon="plus" iconColor="#fff" shape="circle" color="#FFAD4D"
				@click="$jump.nav('/mypackage/user/address_info?type=' + 1)">

			</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageHeight: '',
				user_id: '',
				page: 1,
				status: 'nomore',
				loadmore: [],
				list: [],
			}
		},

		onLoad() {
			let app = uni.getSystemInfoSync()
			this.pageHeight = app.windowHeight - 280
		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			const token = uni.getStorageSync('token');
			this.user_id = uni.getStorageSync('user_id');
			if (token) {
				//如果存在token
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 10 // 滚动动画时长，默认300ms
				});
				this.page = 1
				this.getAddresslist()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {

				uni.showToast({
					title: '您还未登录，正在前往登录',
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: "/mypackage/user/login"
					})
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getProductList()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			async getAddresslist() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/user_add_list/" + this.user_id, {
					page: this.page
				})
				if (code == 200) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else if (code == 500) {
					this.list = data
					this.loadmore = data
				} else {
					console.log(message);
				}
			},
			onReturn: function(item) {
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				let object = {
					address_id: item.id,
					username: item.username,
					phone: item.phone,
				};
				prevPage.$vm.prevDateFun(object) // 调用上一页 定义的方法
				setTimeout(function() {
					uni.navigateBack()
				}, 1200)
			},
		}
	}
</script>

<style scoped lang="less">
	.head_back {}
</style>